home *** CD-ROM | disk | FTP | other *** search
- unit Ddctrl;
-
- interface
-
- uses
- SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
- Forms, Dialogs, DB, DBTables, inifiles, grids;
- const
- FieldTypeStr : array[ftunknown..ftgraphic] of string[8] =
- ('Unknown', 'String', 'Smallint', 'Integer', 'Word',
- 'Boolean', 'Float', 'Currency', 'BCD', 'Date', 'Time',
- 'DateTime', 'Bytes', 'VarBytes', 'Blob', 'Memo', 'Graphic');
- FieldTypeLtr : array[ftunknown..ftgraphic] of string[1] =
- ('U', 'S', 'I', 'N', 'W',
- 'L', 'F', 'C', 'B', 'D', 'T',
- 'A', 'Y', 'V', 'O', 'M', 'G');
-
- type
- DDValidationtype = (IsValidDD, DoesNotExist, ExistbutnotDD, NewDD, EmptyString );
-
- TDataDictCtrlForm = class(TForm)
- DictDB: TDatabase;
- DictTable: TTable;
- DictQuery: TQuery;
- DictSource: TDataSource;
- { tdictctrl = class(TComponent)}
- private
- FiniFile : TiniFile;
- FCtrlDictName : Tfilename; {fully qualified name}
- FDictStatus : DDValidationType;
- FDBSGGood : boolean;
- FTableList : tStrings;
- FDBSG : Tstringgrid; {non-documentation part of dictionary}
- FUpdated : Tdatetime; {info on current dictionary}
- FDictsize : longint;
- FnumRecords,
- Fnumtables,
- FnumFields : integer;
- procedure ReadIniFile;
- function getDictPath : tfilename;
- procedure setDictPath( tmpstr : tfilename);
- function getDictTable : tfilename;
- procedure setDictTable (tmpstr : tfilename);
- protected
- Constructor create(Aowner : Tcomponent); override;
- function OpenDD(const pathname, tablename : string): boolean;
- function CheckOutDD(const Fulltablename : string): DDValidationtype;
-
- { Protected declarations }
- public
-
- { Public declarations }
- published
- property DictStatus: DDValidationType read FDictStatus;
- property FullDDName : tFilename read FCtrlDictName write FCtrlDictName;
- property DictPathName: Tfilename read getDictPath;
- property DictTableName: Tfilename read getDictTable;
- property LastUpdate: tDateTime read Fupdated;
- property DictSize: longint read FDictSize;
- property NumRecords: integer read FNumRecords;
- property numtables: integer read fNumtables;
- property numfields: integer read fNumFields;
- property DBSGExists : boolean read FDBSGGood;
- end;
-
-
- procedure Register;
-
- var
- { DictCtrl : TDictCtrl;}
- DataDictCtrlForm: TDataDictCtrlForm;
-
- implementation
-
- {$R *.DFM}
- uses utils;
- const
- {indexes into DBSG columns}
- tablename = 0; {string 20}
- tabletype = 1; {string 20}
- fieldname = 2; {string[20];}
- tag = 3; {string 20 tfield.tag}
- scrprompt = 4; {string[40]; {tfield.DisplayName}
- scrformat = 5; {string[80]; {tfield.DisplayText -- an editmask}
- grdprompt = 6; {string[10];}
- grdwidth = 7; {smallint {tfield.DisplayWidth}
- fldtype = 8; {string[1]; {FieldTypeLtr}
- fldlen = 9; {smallint {tfield.size}
- flddec = 10; {smallint}
- fldidx = 11; {boolean;}
- idxexp = 12; {string;}
- tab_order = 13; {integer;}
- isrequired = 14; {boolean; {tfield.required}
- defaultis = 15; {string[80];}
- editmaskis = 16; {string[80]; {tfield.editMask}
- minval = 17; {ftfloat tfield.minvalue}
- maxval = 18; {ftfloat tfield.maxvalue}
- vallist = 19; {ftmemo list of valid strings}
- { define documentation only
- validvalue documentation only
- notes documentation only}
- hintTxt = 20; {string 120}
- helpid = 21; {longint;}
- {help, memo only used if helpid not null or 0}
- haslink = 22; {boolean;}
- srclinktbl = 23; {string[20];}
- srclinkfld = 24; {string[20];}
- iscalc = 25; {boolean;}
- formula = 26; {memo only used if iscalc true}
- type
- TDictCtrlStringGrid = TStringGrid;
- var
- DBSG : TDictCtrlStringGrid;
-
- Procedure TDataDictCtrlForm.ReadIniFile;
- begin
- FIniFile := TiniFile.Create(appname+'.ini');
- FCtrlDictName := FiniFile.ReadString('CtrlDict', 'current', appname+'.dbf');
- FiniFile.free;
- end;
-
- function TDataDictCtrlForm.getDictPath : tfilename;
- begin
- result := extractFilePath(FCtrlDictName);
- end;
- procedure TDataDictCtrlForm.setDictPath( tmpstr : tfilename);
- begin
- FCtrlDictName := tmpstr;
- end;
- function TDataDictCtrlForm.getDictTable : tfilename;
- begin
- result := extractFileName(FCtrlDictName);
- end;
- procedure TDataDictCtrlForm.setDictTable (tmpstr : tfilename);
- begin
- end;
-
- constructor TDataDictCtrlForm.create(Aowner : Tcomponent);
- begin
- inherited create(Aowner);
- readIniFile;
- DictDB.Databasename := 'DataDictCtrlFormDB';
- if CheckOutDD(FCtrlDictName) = IsValidDD
- then begin
- {first check it out}
- {pull data into stringgrid?
- or set up a permanent link/ query table
- with data to modify current app
- }
- end
- else begin
- {some kind of message about no dictionary
- present?
- }
- end;
- end;
-
-
- function TDataDictCtrlForm.openDD(const pathname, tablename : string): boolean;
- begin
- try
- DictDB.close;
- DictDB.Params.clear;
- DictDB.Params.Add('PATH='+PathName);
- DictDB.open;
- DictTable.DatabaseName:= DictDB.databasename;
- DictTable.tablename := TableName;
- DictTable.Active:= True;
- DictSource.DataSet:= DictTable;
- DictQuery.databaseName := DictDB.databasename;
- DictQuery.dataSource := DictSource;
- DictQuery.close;
- DictQuery.sql.clear;
- DictQuery.params.clear;
- result := true;
- except
- on EdataBaseError do begin
- screen.cursor := crDefault;
- MessageDlg('Could not open '+pathname + ' '+tablename, mtInformation, [mbOK], 0);
- result := false;
- end;
- end; {of exceptions}
- end;
-
- function TDataDictCtrlForm.CheckOutDD(const Fulltablename : string): DDValidationtype;
- var
- tablefound : boolean;
- sqlstr,
- thistable : string;
- tablenum : integer;
- FileInfo : TsearchRec;
- tableField : tField;
-
- begin
- result := isValidDD;
- fnumtables := 0; fnumFields := 0; fDictsize := 0; fNumRecords := 0;
- FTableList := tstringlist.create;
- if fileExists(fulltablename)
- then begin
- FindFirst(fulltablename, faAnyfile, fileinfo);
- FUpdated := fileDateToDateTime(Fileinfo.time);
- fDictSize := FileInfo.size;
- {not total size, should also get size of .dbt }
- end
- else begin
- result := DoesNotExist;
- exit;
- end;
- if openDD(DictPathName, DictTableName)
- then begin
- fnumrecords := DictTable.RecordCount;
- sqlstr := 'SELECT * FROM '+DictTableName;
- Dictquery.sql.add(sqlstr);
- Dictquery.prepare;
- Dictquery.open;
- Dictquery.first;
- { get tablenames in data dictionary, stick in M_tableList lines}
- if DictQuery.findfield('TABLE_NAME') = nil
- then begin
- result := ExistButNotDD;
- exit;
- end;
- ftableList.add(DictQuery.findfield('TABLE_NAME').text); {get first one}
- inc(fnumfields);
- DictQuery.next;
- while not DictQuery.eof do begin
- tablefound := false;
- thistable := DictQuery.findfield('TABLE_NAME').text;
- inc(fnumFields);
- for tablenum := 0 to ftablelist.count - 1 do
- if ftableList.strings[tablenum] = thistable
- then begin
- tablefound := true;
- break;
- end;
- {done looking for thistable}
- if not tablefound
- then ftablelist.add(thistable);
- DictQuery.next;
- end; {while searching for table names}
- DictQuery.close;
- end
- else begin
- result := ExistbutnotDD;
- end;
- end;
-
-
- procedure Register;
- begin
- RegisterComponents('Synature', [tdatadictctrlform]);
- end;
-
- Initialization
-
- DataDictCtrlForm.Create(application);
-
- end.
-